<template>
  <div class="survey-box">
    <el-row type="flex" justify="space-between" align="middle" class="survey-hedaer">
      <div class="title">用户概况及趋势</div>
      <box-header-right :school="hasSchool" @update:date="updateDate" @update:school="changeSchool" />
    </el-row>
    <el-row type="flex" class="user" :gutter="24">
      <el-col :span="4">
        <div class="item">
          <div class="title"><count-roll :number="response.total" /></div>
          <div class="name">累计用户</div>
        </div>
      </el-col>
      <el-col :span="4">
        <div class="item">
          <div class="title"><count-roll :number="response.register_count" /></div>
          <div class="name">新增用户</div>
        </div>
      </el-col>
      <el-col :span="4">
        <div class="item">
          <div class="title"><count-roll :number="response.payment_user_count_total" /></div>
          <div class="name">累计付费用户</div>
        </div>
      </el-col>
      <el-col :span="4">
        <div class="item">
          <div class="title"><count-roll :number="response.payment_user_count" /></div>
          <div class="name">新增付费用户</div>
        </div>
      </el-col>
      <el-col :span="4">
        <div class="item">
          <div class="title"><count-roll :number="response.vip_user_count_total" /></div>
          <div class="name">累计会员</div>
        </div>
      </el-col>
      <el-col :span="4">
        <div class="item">
          <div class="title"><count-roll :number="response.vip_user_count" /></div>
          <div class="name">新增会员</div>
        </div>
      </el-col>
    </el-row>
    <el-row class="ve-line-box"><ve-line :loading="loading" :data="chartData" :settings="chartSettings" :colors="colors" :extend="extendsConfig" /></el-row>
  </div>
</template>

<script>
import VeLine from 'v-charts/lib/line.common';
import 'v-charts/lib/style.css';
import BoxHeaderRight from '../../../components/daterange.vue';
import CountRoll from '@/pages/data/components/count_roll';
export default {
  components: {
    VeLine,
    BoxHeaderRight,
    CountRoll
  },
  data() {
    return {
      daterange: null,
      mhm_id: 0,
      loading: false,
      hasSchool: false,
      response: {},
      chartSettings: {
        labelMap: {
          date: '日期',
          student: '新增用户',
          payment: '新增付费用户',
          vip: '新增会员'
        },
        yAxisName: ['人数']
      },
      extendsConfig: {
        series: {
          smooth: false
        },
        grid: {
          right: 20,
          left: 20
        },
        xAxis(v) {
          v.forEach(i => {
            i.boundaryGap = false;
            i.axisLabel = {
              showMaxLabel: true,
              rotate: 65
            };
          });

          return v;
        },
        yAxis(v) {
          v.forEach(i => {
            i.minInterval = 1;
          });

          return v;
        }
      },
      colors: ['#67C23A', '#B849FF', '#FFA261'],
      chartData: {
        columns: ['date', 'student', 'payment', 'vip'],
        rows: []
      }
    };
  },
  created() {
    this.loadData();
  },
  methods: {
    updateDate: function(date) {
      this.daterange = date;
      this.loading = true;
      this.loadData();
    },
    changeSchool: function(mhm) {
      this.mhm_id = mhm;
      this.loading = true;
      this.loadData();
    },
    loadData: function() {
      this.$http.get(
        '/admin/data/student/survey',
        {
          daterange: this.daterange,
          mhm_id: this.mhm_id
        },
        response => {
          this.response = response.data;
          this.chartData.rows = this.response.rows;
          this.hasSchool = !!this.response.is_platform;
          this.loading = false;
        },
        errror => {
          this.loading = false;
        },
        false
      );
    }
  }
};
</script>

<style lang="scss" scoped>
.survey-box {
  background-color: #fff;
  min-height: 150px;
  margin-bottom: 20px;
  padding: 10px 20px 25px;
  .survey-hedaer {
    margin-bottom: 28px;
    height: 36px;
    padding-right: 20px;
    background-color: #f1f8ff;
    .title {
      color: #303133;
      font-size: 15px;
      padding-left: 6px;
      border-left: 2px solid #5191ff;
    }
  }
  .user {
    .el-col:nth-child(1) .item {
      background: linear-gradient(226deg, rgba(255, 212, 65, 1) 0%, rgba(250, 165, 0, 1) 100%);
    }
    .el-col:nth-child(2) .item {
      background: linear-gradient(226deg, rgba(115, 164, 255, 1) 0%, rgba(60, 143, 255, 1) 100%);
    }
    .el-col:nth-child(3) .item {
      background: linear-gradient(226deg, rgba(255, 172, 118, 1) 0%, rgba(255, 142, 70, 1) 100%);
    }
    .el-col:nth-child(4) .item {
      background: linear-gradient(225deg, rgba(173, 232, 89, 1) 0%, rgba(131, 219, 49, 1) 100%);
    }
    .el-col:nth-child(5) .item {
      background: linear-gradient(226deg, rgba(255, 149, 132, 1) 0%, rgba(255, 113, 105, 1) 100%);
    }
    .el-col:nth-child(6) .item {
      background: linear-gradient(45deg, rgba(123, 114, 255, 1) 0%, rgba(135, 161, 255, 1) 100%);
    }
    .item {
      padding: 18px;
      text-align: center;
      border-radius: 4px;
      .title {
        color: #fff;
        font-weight: bold;
        font-size: 22px;
      }
      .name {
        color: #fff;
        font-size: 14px;
        margin-top: 13px;
      }
    }
  }
  .ve-line-box {
    margin-top: 24px;
    border: 1px solid #e4e7ed;
    padding: 20px 20px 0 20px;
  }
}
</style>
